package com.adtec.base.cloud.wechatservice.wechatcloud.wechat.controller;


import com.adtec.base.cloud.commons.exception.AjaxResponse;
import com.adtec.base.cloud.persistence.wechat.model.WechatEnterprise;
import com.adtec.base.cloud.wechatservice.wechatcloud.wechat.service.EnterpriseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/wechatEnterprise")
@Tag(name = "wechatEnterprise", description = "企业微信企业信息相关接口")
public class EnterpriseController {
    @Resource
    private EnterpriseService enterpriseService;

    @PostMapping(value = "/addEnterprise")
    @Operation(description = "新增企业")
    public AjaxResponse addEnterprise(@RequestBody WechatEnterprise wechatEnterprise) {
        enterpriseService.addEnterprise(wechatEnterprise);
        return AjaxResponse.success("新增企业成功");
    }

    @PostMapping(value = "/updateEnterprise")
    @Operation(description = "修改企业")
    public AjaxResponse updateEnterprise(@RequestBody WechatEnterprise wechatEnterprise) {
        enterpriseService.updateEnterprise(wechatEnterprise);
        return AjaxResponse.success("修改企业成功");
    }

    @PostMapping(value = "/deleteEnterprise")
    @Operation(description = "删除企业")
    @Parameters({@Parameter(name = "id", description = "企业ID"),})
    public AjaxResponse deleteEnterprise(@RequestParam Long id) {
        enterpriseService.deleteEnterprise(id);
        return AjaxResponse.success("删除企业成功");
    }

    @PostMapping(value = "/query")
    @Operation(description = "查询企业")
    @Parameters({@Parameter(name = "enterpriseName", description = "企业名称(模糊查询)"),})
    public List<WechatEnterprise> query(@RequestParam(name = "enterpriseName", required = false) String enterpriseName) {
        return enterpriseService.query(enterpriseName);
    }


}
